package com.yonyou.pmclouds.plan.entity;


import com.yonyou.pmclouds.basecom.entity.TreeVO;
import com.yonyou.pmclouds.basecom.ref.itf.TreeVODependencyitf;
import com.yonyou.pmclouds.plan.planindex.entity.PlanIndexVO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.*;

@EqualsAndHashCode(callSuper = true)
@Data
@Table(name = "pm_schedule_item")
public class ScheduleItemVO extends TreeVO implements TreeVODependencyitf {

    private static final long serialVersionUID = -9041573364023601331L;

    public static final String MANAGER = "manager";

    public static final String MANAGER_NAME = "managerName";

    public static String CREATOR = "creator";

    public static String CREATOR_NAME = "creatorName";

    public static String CODE = "code";

    public static final String PLAN_FINISHER = "planFinisher";

    public static final String PLAN_FINISHER_NAME = "planFinisherName";

    public static final int SCHEDULE_ITEM_COMPLETE = 100;

    public static final String[] UPDATE_FIELDS = {"name", "code" ,"dependPlan", "planStartDate", "planEndDate",
            "planDays", "description", "manager", "pkMilestone", "relatedBillType", "indexNumber",
            "completedStatus", "pkDepartment", "planFinisher", "relatedPkBill", "modifier", "modifytime", "changeFlag"};

    @Id
    @NotNull(groups = UpdateValid.class)
    private String pkScheduleItem;

    private String pkSchedule;

    private String pkProject;

    @Size(max = 50)
    @NotNull
    private String name;

    private String code;

    private int seq;

    private String dependPlan;

    @NotNull
    private Date planStartDate;

    @NotNull
    private Date planEndDate;

    @NotNull
    private Integer planDays;

    @Size(max = 300)
    private String description;

    private String pkRoot;

    private Integer childCount;

    private String creator;

    private Date creationtime;

    private String modifier;

    private Date modifytime;

    private String pkSrc;

    private int version;

    private String pkOriginal;

    private String pkMilestone;

    private String relatedBillType;

    private Integer indexNumber;

    private Byte completedStatus;

    private String pkDepartment;

    private String planFinisher;

    private String relatedPkBill;

    @Transient
    private ScheduleItemVO[] children;

    @Transient
    private PlanProgressVO progressVO;

    // 是否延期
    @Transient
    private Boolean isDelay;

    // 前端表格组件使用，存在主键值，唯一
    @Transient
    private String key;

    @Transient
    private String dependPlanName;

    // 前置计划对象，甘特图取值使用
    @Transient
    private ScheduleItemVO[] dependPlans;

    @Transient
    private String planFinisherName;

    @Transient
    private String managerName;
    @Transient
    private String[] pictures;

    @Transient
    private PlanTempletVO templetVO;
    @Transient
    private String pkPlanwrite;
    @Transient
    private byte status;//计划填报的审批状态展示字段
    @Transient
    private String mark;//计划展示不展示标记
    @Transient
    private String departmentName;

    @Transient
    private String changeRecordFlag;//修改标记1 新增 0修改 -1 删除

    @Transient
    private List<String> changeRecords;//修改内容

    /**
     * 里程碑编码、名称
     */
    @Transient
    private String milestoneCode;
    @Transient
    private String milestoneName;
    /**
     * 关联单据类型名称
     */
    @Transient
    private String relatedBillTypeName;
    /**
     * 计划关联的指标
     */
    @Transient
    private List<PlanIndexVO> planIndexVOs;
    /**
     * 计划要删除的指标
     */
    @Transient
    private List<String> deletePlanIndexes;
    @Transient
    private TreeVO[] child;
    @Transient
    private String pk;


    @Override
    public String findPk() {
        return this.pkScheduleItem;
    }

    @Override
    public TreeVODependencyitf[] findChildren() {
        return this.children;
    }

    @Override
    public String[] findOtheDependency() {
        if (StringUtils.isEmpty(dependPlan)) return null;
        return new String[]{dependPlan};
    }

    @Override
    public String findCode() {
        return this.code;
    }

    @Override
    public void setPk(String pk) {
      this.pkScheduleItem = pk;
    }

    @Override
    @Transient
    public String getPk() {
       return this.pkScheduleItem;
    }

    @Override
    @Transient
    public TreeVO[] getChild() {
        return this.children;
    }

    @Override
    public void setChild(TreeVO[] child) {
        if(child != null && child.length > 0 && child[0] instanceof ScheduleItemVO){
            this.children = (ScheduleItemVO[]) child;
        }
    }

    public interface UpdateValid {
    }

    public interface InsertValid {
    }
}
